# coding=utf-8
import maya.cmds as cmds
import logging
class FootPositioning():
	def Win(self):
		windowName = u'脚步定位工具' 
		if cmds.window (windowName,ex = 1):
			cmds.deleteUI (windowName)
		window  = cmds.window (windowName,sizeable = 0,widthHeight=	(300, 50))
		cmds.rowLayout( numberOfColumns=2)
		cmds.button(u"《---",h=50,w=150,c =lambda *args: self.left_Move() )
		cmds.button(u"---》",h=50,w=150,c =lambda *args: self.right_Move() )
		cmds.setParent( '..' )
		cmds.showWindow(window)

	def left_Move(self):
		logging.basicConfig(level = logging.INFO,format = '%(asctime)s - %(name)s - %(levelname)s - %(message)s')
		logger = logging.getLogger(__name__)
		# 创建一个控制台处理器
		console_handler = logging.StreamHandler()
		self.selectObj = cmds.ls(sl = 1)
		if len(self.selectObj) >1:
			return (logger.error(u"选择物体不能大于一" ))
		elif len(self.selectObj) <1:
			return(logger.error(u'选择物体不能为零'))
		self.translate = cmds.xform(self.selectObj[0],q=1 ,worldSpace = 1,translation=1 )
		self.rotate= cmds.xform(self.selectObj[0],q=1 ,worldSpace = 1,rotation=1 )  
		starTime = cmds.currentTime( query=True )
		cmds.currentTime( starTime-1, edit=True )
		cmds.xform(self.selectObj[0],worldSpace=True,translation=self.translate )
		cmds.xform(self.selectObj[0],worldSpace=True,rotation=self.rotate )
		cmds.setKeyframe (self.selectObj[0])
		
	def right_Move(self):
		logging.basicConfig(level = logging.INFO,format = '%(asctime)s - %(name)s - %(levelname)s - %(message)s')
		logger = logging.getLogger(__name__)
		# 创建一个控制台处理器
		console_handler = logging.StreamHandler()
		self.selectObj = cmds.ls(sl = 1)
		if len(self.selectObj) >1:
			return (logger.error(u"选择物体不能大于一" ))
		elif len(self.selectObj) <1:
			return(logger.error(u'选择物体不能为零'))
		self.translate = cmds.xform(self.selectObj,q=1 ,worldSpace = 1,translation=1 )
		self.rotate= cmds.xform(self.selectObj,q=1 ,worldSpace = 1,rotation=1 )
		starTime = cmds.currentTime( query=True )
		cmds.currentTime(  starTime+1, edit=True )
		cmds.xform(self.selectObj,worldSpace=True,translation=self.translate )
		cmds.xform(self.selectObj,worldSpace=True,rotation=self.rotate )
		cmds.setKeyframe (self.selectObj)